<?php
	session_start();
	
	include "dbconnect.php";

	$sem=$_POST["term"];
	$year=$_POST["year"];
	$course=$_POST["courseid"];
	$username=$_SESSION["Username"];
	
	$con=mysql_connect($dbHost,$dbUserAndName,$dbPass);
	mysql_select_db($_DB_NAME,$con);
	
			mysql_query("SET @pterm='".$sem."'");
			mysql_query("SET @pyear=".$year);
			$semidrs=mysql_query("select semid from semester where term=@pterm and year=@pyear");
			
			if($semidrs == false)
			{
				die(mysql_error());
			}
			$semid = mysql_fetch_assoc($semidrs);
			
	mysql_query("SET @semid=".$semid["semid"]);		
	mysql_query("SET @username='".$username."'");
	$yearList =	mysql_query("select distinct courseid from openings where semid=@semid and  instructor  = @username  and isdeleted=0 and courseid like '%".$course."%'");
	
	$year="";
	while($row = mysql_fetch_array($yearList))
	{
		if(empty($year)==true)
		{
  			$year= $row['courseid'];
		}
		else
		{
			$year= $year.",".$row['courseid'];
		}
	}
	mysql_close($con);	
	echo $year;
?>